216C - Hiring Staff - CodeForces Solution


greedy *1800

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <cfloat>
#include <sstream>

using namespace std;

int n, m, i, j, k;
string s, p;
long long M = 1000000007;

void sim()
{
    vector<int> ans;
    set<pair<int, int>> work, rest;
    i = 1;
    while (i <= n + m)
    {
        while (rest.size() && (*rest.begin()).first + m == i)
        {
            pair<int, int> x = *rest.begin();
            rest.erase(x);
            work.insert({i, x.second});
        }
        while (work.size() && (*work.begin()).first + n == i)
        {
            pair<int, int> x = *work.begin();
            work.erase(x);
            rest.insert({i, x.second});
        }
        int f = 0;
        for (auto itr = work.begin(); itr != work.end(); itr++)
            if ((*itr).first + n == i + 1)
                f++;
        if (f == work.size())
        {
            ans.push_back(i);
            work.insert({i, ans.size()});
        }
        while (work.size() < k)
        {
            ans.push_back(i);
            work.insert({i, ans.size()});
        }
        i++;
    }
    cout << ans.size() << "\n";
    for (i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
    return;
}

void solve(int T)
{
    cin >> n >> m >> k;
    sim();
    return;
}

int main()
{
    cin.sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    t = 1;
    for (int i = 1; i <= t; i++)
    {
        solve(t);
        cout << "\n";
    }
}


Comments

Submit
0 Comments
More Questions

1004B - Sonya and Exhibition
1397A - Juggling Letters
985C - Liebig's Barrels
115A - Party
746B - Decoding
1424G - Years
1663A - Who Tested
1073B - Vasya and Books
195B - After Training
455A - Boredom
1099A - Snowball
1651D - Nearest Excluded Points
599A - Patrick and Shopping
237A - Free Cash
1615B - And It's Non-Zero
1619E - MEX and Increments
34B - Sale
1436A - Reorder
1363C - Game On Leaves
1373C - Pluses and Minuses
1173B - Nauuo and Chess
318B - Strings of Power
1625A - Ancient Civilization
864A - Fair Game
1663B - Mike's Sequence
448A - Rewards
1622A - Construct a Rectangle
1620A - Equal or Not Equal
1517A - Sum of 2050
620A - Professor GukiZ's Robot